﻿@using RooHui.Infrastructure.Entities.Entity;
@using RooHui.Tool;
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Base.cshtml";
}
<div id="toptoolbar"></div> 
<div id="promotpolicyid">
</div>
<script type="text/javascript">
    var promotpolicyid;
    $(function () {
        $("#toptoolbar").ligerToolBar({ items: [{ text: '新增', click: grid_promotpolicy_add, icon: "add" },
            { text: '修改', click: grid_promotpolicy_edit, icon: "modify" },
            { text: '删除', click: grid_promotpolicy_delete, icon: "delete" },
            { text: '刷新', click: grid_promotpolicy_refresh, icon: "refresh" }
            ]
        });
        promotpolicygrid = $("#promotpolicygrid").ligerGrid({
            columns: [
                { display: '开始时间', name: 'BeginDate', width: '12%', isSort: false },
                { display: '结束时间', name: 'EndDate', width: '12%', isSort: false },
                { display: '激活代码', name: 'ActiveCode', width: '10%', isSort: false },
                { display: '附件策略', name: 'AttachPolicy', width: '10%', isSort: false },
                { display: '启用', name: 'Enable', width: '10%', isSort: false },
                { display: '创建人', name: 'CreateUser', width: '8%', isSort: false },
                { display: '创建时间', name: 'CreateTime', width: '12%', isSort: false },
                {
                    display: '操作', isAllowHide: false,
                    render: function (row) {
                        var html = '<a href="#" onclick="promotpolicyEdit(\'' + row.ID + '\', -1)">详情</a>&nbsp;&nbsp;<a href="#" onclick="promotpolicyEdit(\'' + row.ID + '\',1)">修改</a>&nbsp;&nbsp;<a href="#" onclick="promotpolicy_delete(\'' + row.ID + '\')">删除</a>';
                        if (row.Status == 1) {
                            html = html + '&nbsp;&nbsp;<a href="#" onclick="changestate(\'' + row.ID + '\',0)">禁用</a>';
                        }
                        else if (row.Status == 0) {
                            html = html + '&nbsp;&nbsp;<a href="#" onclick="changestate(\'' + row.ID + '\',1)">启用</a>';
                        }
                        return html;
                    }
                }
                ],
            width: '100%', height: '100%', rownumbers: true,
            dataAction: 'server',
            url: "/PromotPolicy/GetPromotPolicyListByPage",
            pageSizeOptions: [20],
            pageSize: 20
        });
    });

    function search(page) {
        if (page == 1) {
            promotpolicygrid.setOptions(
             {
                 parms:
                [
                    { name: "page", value: 1 }
                ]
             });
        }
        else {
            promotpolicygrid.setOptions();
        }
        promotpolicygrid.loadData();
    }

    // 添加
    var addDialog;
    function grid_promotpolicy_add() {
        location.href = decodeURIComponent("/PromotPolicy/PromotPolicyAdd");
    }

    function save_promotpolicy() {
        addDialog.frame.save();
    }

    function save_result(result) {
        $.ligerDialog.success("保存成功。");
        addDialog.close();
        search(0);
    }

    // 修改
    var editDialog;
    function grid_promotpolicy_edit() {
        if (promotpolicygrid.getSelecteds().length == 0) {
            $.ligerDialog.warn('选择要修改的记录！', '温馨提示');
            return;
        }
        var promotpolicyID = promotpolicygrid.getSelected().ID;
        promotpolicyEdit(promotpolicyID, 1);
    }

    function promotpolicyEdit(promotpolicyid, edittype) {
        location.href = decodeURIComponent("/PromotPolicy/PromotPolicyEdit?promotpolicyId=" + promotpolicyid + "&editType=" + edittype);
    }

    function grid_promotpolicy_delete() {
        var promotpolicyId = "";

        var selected = promotpolicygrid.getSelecteds();
        if (selected.length == 0) {
            $.ligerDialog.warn('至少选择一条记录进行删除！', '温馨提示');
            return;
        }

        for (var i = 0; i < selected.length; i++) {
            promotpolicyId += selected[i].ID + ",";
        }
        promotpolicyId = promotpolicyId.substring(0, promotpolicyId.length - 1);
        promotpolicy_delete(promotpolicyId);

    }

    // 删除
    function promotpolicy_delete(promotpolicyId) {
        $.ligerDialog.confirm('确定要删除选中的记录吗？', '温馨提示', function (result) {
            if (result) {
                $.ajax({
                    url: '/PromotPolicy/PromotPolicyDelete',
                    data: "id=" + promotpolicyId,
                    type: "post",
                    success: function (result) {
                        if (result == "OK") {
                            $.ligerDialog.success("删除成功！");
                            grid_promotpolicy_refresh();
                        } else {
                            $.ligerDialog.error('删除失败！', '温馨提示');
                        }
                    }
                });
            }
        });
    }

    // 刷新
    function grid_promotpolicy_refresh() {
        promotpolicygrid.setOptions(
             {
                 parms:
                [
                    { name: "page", value: 1 }
                ]
             });
        promotpolicygrid.loadData();
    }
 
         
  
</script>